package com.aopmin.ws.task;

import com.aopmin.ws.config.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 简单测试定时任务
 *
 * @Author mr.wu
 * @Date 2025-5-30 9:29
 */
@Component
public class SpringTaskDemo {

    @Autowired
    private WebSocketServer webSocketServer;


    /**
     * 每10秒群发一次消息到客户端
     */
    // @Scheduled(cron = "*/10 * * * * ?")
    public void printTime() {
        webSocketServer.sendMsgToAll(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    }
}
